﻿using Microsoft.VisualStudio.Text.Classification;

namespace Language.Syntax.Colouring
{
    enum ClassificationType
    {
        Comment,
        Keyword,
        Integral,

        LiteralInteger,
        LiteralFloat,
        LiteralString,
        LiteralName,

        Class,
        NativeClass,

        Function,
        FunctionCall,
        MethodCall,
        NativeFunctionCall,
        NativeMethodCall,

        Identifier,
        Local,
        Parameter,
        Member,

        Enum,
        EnumOption,
        NativeEnum,
        NativeEnumOption,

        Count
    }

    internal class ClassificationTypes
    {
        #region Private Data

        private IClassificationType[] _classifications = new IClassificationType[ (int)ClassificationType.Count ];

        #endregion Private Data

        #region Public Properties

        public IClassificationType this[ ClassificationType type ] => _classifications[ (int)type ];

        #endregion Public Properties

        #region C-Tor

        public ClassificationTypes( IClassificationTypeRegistryService registry )
        {
            Insert( registry, ClassificationType.Comment, Classification.Name.Comment );
            Insert( registry, ClassificationType.Keyword, Classification.Name.Keyword );
            Insert( registry, ClassificationType.Integral, Classification.Name.Integral );

            Insert( registry, ClassificationType.LiteralInteger, Classification.Name.LiteralInteger );
            Insert( registry, ClassificationType.LiteralFloat, Classification.Name.LiteralFloat );
            Insert( registry, ClassificationType.LiteralString, Classification.Name.LiteralString );
            Insert( registry, ClassificationType.LiteralName, Classification.Name.LiteralName );

            Insert( registry, ClassificationType.Class, Classification.Name.Class );
            Insert( registry, ClassificationType.NativeClass, Classification.Name.NativeClass );

            Insert( registry, ClassificationType.Function, Classification.Name.Function );
            Insert( registry, ClassificationType.FunctionCall, Classification.Name.FunctionCall );
            Insert( registry, ClassificationType.MethodCall, Classification.Name.MethodCall );
            Insert( registry, ClassificationType.NativeFunctionCall, Classification.Name.NativeFunctionCall );
            Insert( registry, ClassificationType.NativeMethodCall, Classification.Name.NativeMethodCall );

            Insert( registry, ClassificationType.Identifier, Classification.Name.Identifier );
            Insert( registry, ClassificationType.Local, Classification.Name.Local );
            Insert( registry, ClassificationType.Parameter, Classification.Name.Parameter );
            Insert( registry, ClassificationType.Member, Classification.Name.Member );

            Insert( registry, ClassificationType.Enum, Classification.Name.Enum );
            Insert( registry, ClassificationType.EnumOption, Classification.Name.EnumOption );
            Insert( registry, ClassificationType.NativeEnum, Classification.Name.NativeEnum );
            Insert( registry, ClassificationType.NativeEnumOption, Classification.Name.NativeEnumOption );
        }

        #endregion C-Tor

        #region Private Methods

        private void Insert( IClassificationTypeRegistryService registry, ClassificationType type, string name )
        {
            _classifications[ (int)type ] = registry.GetClassificationType( name );
        }

        #endregion Private Methods
    }
}
